local L = LibStub("AceLocale-3.0"):GetLocale("zHunterMod")
local vertical = {TOP=L["Top"], BOTTOM=L["Bottom"]}
local horizontal = {LEFT=L["Left"], RIGHT=L["Right"]}
local mouseEvents = {OnRightClick=L["On Right-Click"], OnMouseOver=L["On Mouse Over"], Always=L["Always Shown"]}

ZHunterModOptions = {
	type = "group",
	args = {
		autoshot = {
			type = "group",
			name = L["Auto Shot Bar"],
			desc = L["Options to customize the Auto Shot Bar."],
			order = 1,
			args = {
				use = {
					type = "toggle",
					name = L["Toggle Use"],
					desc = L["Toggle the display of the Auto Shot Bar."],
					get = function(info) return ZHunterMod_Saved.ZAutoShot.on end,
					set = function(info, v) ZHunterMod_Saved.ZAutoShot.on = v end
				}
			}
		},
		other = {
			type = "group",
			name = L["Other Features"],
			desc = L["Enable/disable various other features that are available."],
			order = 9,
			args = {
				autostrip = {
					type = "toggle",
					name = L["Auto Strip Button"],
					desc = L["Toggle the display of the Auto Strip Button."],
					get = function(info) return ZHunterMod_Saved["ZAutoStrip"]["on"] end,
					set = function(info, v)
						ZHunterMod_Saved["ZAutoStrip"]["on"] = v
						if v then
							ZAutoStrip:Show()
						else
							ZAutoStrip:Hide()
						end
					end
				},
				antidaze = {
					type = "toggle",
					name = L["Anti Daze"],
					desc = L["Toggle the display of the Aspect Bar."],
					get = function(info) return ZHunterMod_Saved["ZAntiDaze"]["on"] end,
					set = function(info, v) ZHunterMod_Saved["ZAntiDaze"]["on"] = v end
				}
			}
		}
	}
}
--/script SetBinding("J", "CLICK ZPet:LeftButton")
--/script local a,b,c=GetBindingAction("CLICK ZPet:LeftButton") Print(a) Print(b) Print(c)
--/script local a,b,c=GetBindingKey("CLICK ZPet:LeftButton") Print(a) Print(b) Print(c)

local function removeBindings(action)

end

do
	local buttons = {"ZAspect", "ZTrack", "ZTrap", "ZPet"}
	for i = 1, 4 do
		ZHunterModOptions.args[buttons[i].."Binds"] = {
			type = "group",
			name = buttons[i]..L[" Bindings"],
			desc = L["Set keybindings to "] .. buttons[i] .. L[" buttons."],
			order = 9 + i,
			args = {}
		}
		local tbl = ZHunterModOptions.args[buttons[i].."Binds"]
		for j = 1, 12 do
			local button = buttons[i] .. (j == 1 and "" or j)
			tbl.args["button"..j] = {
				type = "keybinding",
				order = j,
				name = buttons[i] .. L[" Button "] .. j,
				desc = L["Set the key binding for "] .. buttons[i] .. ".",
				get = function(info)
					local key = GetBindingKey("CLICK " .. button .. ":LeftButton")
					return key
				end,
				set = function(info, v)
					SetBinding(v, "CLICK " .. button .. ":LeftButton")
					SaveBindings(GetCurrentBindingSet());
				end
			}
		end
	end
end

LibStub("AceConfig-3.0"):RegisterOptionsTable("ZHunterMod", ZHunterModOptions)

function ZHunterModOptions_SetSpellOptions(name, tbl, spells)
	tbl.enable = {
		type = "toggle",
		name = L["Enable"], desc = L["Enable or disable the button's use."],
		order = 1,
		get = function(info) return ZHunterMod_Saved[name].enabled end,
		set = function(info, v)
			ZHunterMod_Saved[name].enabled = v
			local frame = getglobal(name)
			if v then
				frame:SetCount(ZHunterMod_Saved[name].count)
				frame:Show()
			else
				frame:SetCount(0)
				frame:Hide()
			end
		end
	}
	tbl.size = {
		type = "range", min = 20, max = 50, step = 1,
		name = L["Button Size"], desc = L["Changes the size of the spell buttons."],
		order = 2,
		get = function(info) return ZHunterMod_Saved[name].size end,
		set = function(info, v)
			ZHunterMod_Saved[name].size = v
			getglobal(name):SetSize(v)
		end
	}
	tbl.roundButton = {
		type = "toggle",
		name = L["Round Button"], desc = L["Set the button border to be round."],
		order = 3,
		get = function(info) return ZHunterMod_Saved[name].roundButton end,
		set = function(info, v)
			ZHunterMod_Saved[name].roundButton = v
			getglobal(name):SetRoundButton(v)
		end
	}
	tbl.bgColor = {
		type = "color", hasAlpha = false,
		name = L["Border Color"], desc = L["Set the color of the border."],
		order = 4,
		get = function(info) return ZHunterMod_Saved[name].bgColor.r, ZHunterMod_Saved[name].bgColor.g, ZHunterMod_Saved[name].bgColor.b end,
		set = function(info, r, g, b)
			ZHunterMod_Saved[name].bgColor.r = r
			ZHunterMod_Saved[name].bgColor.g = g
			ZHunterMod_Saved[name].bgColor.b = b
			getglobal(name):SetBackgroundColor(ZHunterMod_Saved[name].bgColor)
		end
	}
	tbl.count = {
		type = "range", min = 0, max = #spells + 1, step = 1,
		name = L["Number of Buttons"], desc = L["Set the number of buttons to show on the bar."],
		order = 5,
		get = function(info) return ZHunterMod_Saved[name].count end,
		set = function(info, v)
			ZHunterMod_Saved[name].count = v
			getglobal(name):SetCount(v)
		end
	}
	tbl.perRow = {
		type = "range", min = 1, max = #spells + 1, step = 1,
		name = L["Buttons Per Row"], desc = L["Set the number of rows on which to display the bar."],
		order = 6,
		get = function(info) return ZHunterMod_Saved[name].perRow end,
		set = function(info, v)
			ZHunterMod_Saved[name].perRow = v
			getglobal(name):SetPerRow(v)
		end
	}
	tbl.horizontal = {
		type = "select", style = "dropdown", values = horizontal,
		name = L["Column Direction"], desc = L["Set whether columns expand to the left or right of eachother.."],
		order = 7,
		get = function(info) return ZHunterMod_Saved[name].horizontal end,
		set = function(info, v)
			ZHunterMod_Saved[name].horizontal = v
			getglobal(name):SetHorizontal(v)
		end
	}
	tbl.vertical = {
		type = "select", style = "dropdown", values = vertical,
		name = L["Row Direction"], desc = L["Set whether the rows will stack on the top or bottom of eachother."],
		order = 8,
		get = function(info) return ZHunterMod_Saved[name].vertical end,
		set = function(info, v)
			ZHunterMod_Saved[name].vertical = v
			getglobal(name):SetVertical(v)
		end
	}
	tbl.expandType = {
		type = "select", style = "dropdown", values = mouseEvents,
		name = L["Expand Type"], desc = L["Set the event to make the bar expand."],
		order = 9,
		get = function(info) return ZHunterMod_Saved[name].expandType end,
		set = function(info, v)
			ZHunterMod_Saved[name].expandType = v
			getglobal(name):SetExpandType(v)
		end
	}
	for i = 1, #spells do
		tbl["button"..i] = {
			type = "select", style = "dropdown", values = spells,
			name = L["Button "]..i, desc = L["Select which spell to use for this button."],
			order = 25 + i,
			get = function(info) return ZHunterMod_Saved[name].order[i] end,
			set = function(info, v)
				ZHunterMod_Saved[name].order[i] = v
				getglobal(name):UpdateSpells()
			end
		}
	end
end

function ZHunterModOptions_SetBroadcastOptions(name, tbl)
	tbl.print = {
		type = "toggle", tristate = true,
		name = L["Print"], desc = L["Prints the message to your default chat frame."],
		order = 10,
		get = function(info) return ZHunterMod_Saved[name].print end,
		set = function(info, v) ZHunterMod_Saved[name].print = v end
	}
	tbl.yell = {
		type = "toggle", tristate = true,
		name = L["Yell"], desc = L["Broadcasts the message through yells."],
		order = 11,
		get = function(info) return ZHunterMod_Saved[name].yell end,
		set = function(info, v) ZHunterMod_Saved[name].yell = v end
	}
	tbl.party = {
		type = "toggle", tristate = true,
		name = L["Party"], desc = L["Broadcasts the message through party chat."],
		order = 12,
		get = function(info) return ZHunterMod_Saved[name].party end,
		set = function(info, v) ZHunterMod_Saved[name].party = v end
	}
	tbl.raid = {
		type = "toggle", tristate = true,
		name = L["Raid"], desc = L["Broadcasts the message through raid chat."],
		order = 13,
		get = function(info) return ZHunterMod_Saved[name].raid end,
		set = function(info, v) ZHunterMod_Saved[name].raid = v end
	}
	tbl.raidWarning = {
		type = "toggle", tristate = true,
		name = L["Raid Warning"], desc = L["Broadcasts the message through raid warnings."],
		order = 14,
		get = function(info) return ZHunterMod_Saved[name].raidWarning end,
		set = function(info, v) ZHunterMod_Saved[name].raidWarning = v end
	}
	tbl.channel = {
		type = "toggle", tristate = true,
		name = L["Channel"], desc = L["Broadcasts the message through a custom channel."],
		order = 15,
		get = function(info) return ZHunterMod_Saved[name].channel end,
		set = function(info, v) ZHunterMod_Saved[name].channel = v end
	}
	tbl.channelNum = {
		type = "range", min = 1, max = 10, step = 1,
		name = L["Channel Number"], desc = L["Set the channel number through which to broadcast the message."],
		order = 16,
		get = function(info) return ZHunterMod_Saved[name].channelNum end,
		set = function(info, v) ZHunterMod_Saved[name].channelNum = v end
	}
end